load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbcode_macros//build_defs:thrift_library.bzl", "thrift_library")
load("//fboss:THIRD-PARTY-VERSIONS.bzl", "BCM_SDKS", "to_impl_suffix", "to_versions")
load(
    "//fboss/agent/test/link_tests:link_tests.bzl",
    "all_sai_link_test_binaries",
)

oncall("fboss_agent_push")

cpp_library(
    name = "link_tests",
    srcs = [
        "DependencyTest.cpp",
        "EmptyLinkTest.cpp",
        "LacpSanityTests.cpp",
        "LinkSanityTests.cpp",
        "LinkTest.cpp",
        "LinkTestUtils.cpp",
        "MacLearningTests.cpp",
        "OpenBmcUpgradeTests.cpp",
        "OpticsTest.cpp",
        "PhyInfoTest.cpp",
        "PrbsTest.cpp",
        "PtpTests.cpp",
        "QsfpServiceThriftDeadlockTest.cpp",
        "SpeedChangeTest.cpp",
        "facebook/FsdbTests.cpp",
        "facebook/MacsecFsdbTests.cpp",
        "facebook/MacsecSanityTests.cpp",
        "facebook/MacsecSessionTests.cpp",
        "facebook/MacsecStatTests.cpp",
        "facebook/MacsecTest.cpp",
        "facebook/QsfpFsdbTests.cpp",
    ],
    link_whole = True,
    # Will need symbols from bcm, sai layers. Those
    # will come when we build bcm/sai link test bins
    undefined_symbols = True,
    exported_deps = [
        "fbsource//third-party/googletest:gtest",
        ":link_test_production_features-cpp2-types",
        "//common/base:proc",
        "//fboss/agent:agent_features",
        "//fboss/agent:agent_stats-cpp2-types",
        "//fboss/agent:core",
        "//fboss/agent:fboss-error",
        "//fboss/agent:fboss-types",
        "//fboss/agent:load_agent_config",
        "//fboss/agent:main-common",
        "//fboss/agent:platform_base",
        "//fboss/agent/hw:hardware_stats-cpp2-types",
        "//fboss/agent/hw:hw_switch_warmboot_helper",
        "//fboss/agent/hw/test:config_factory",
        "//fboss/agent/hw/test:hw_packet_utils",
        "//fboss/agent/hw/test:hw_qos_utils",
        "//fboss/agent/hw/test:hw_test_ecmp_utils",
        "//fboss/agent/hw/test:hw_test_fabric_utils",
        "//fboss/agent/hw/test:hw_test_port_utils",
        "//fboss/agent/hw/test:load_balancer_utils",
        "//fboss/agent/packet:packet",
        "//fboss/agent/platforms/common:platform_mapping",
        "//fboss/agent/state:state",
        "//fboss/agent/state:state_utils",
        "//fboss/agent/test:agent_test",
        "//fboss/agent/test:ecmp_helper",
        "//fboss/agent/test:resourcelibutil",
        "//fboss/agent/test:trunk_utils",
        "//fboss/agent/test:utils",
        "//fboss/agent/test/utils:copp_test_utils",
        "//fboss/agent/test/utils:packet_snooper",
        "//fboss/agent/test/utils:pkt_test_utils",
        "//fboss/agent/test/utils:port_test_utils",
        "//fboss/agent/test/utils:qos_test_utils",
        "//fboss/agent/test/utils:trap_packet_utils",
        "//fboss/facebook/mka_service/fsdb/tests:MKAFsdbTestUtils",
        "//fboss/facebook/mka_service/mka_module:mka_structs",
        "//fboss/fsdb/client:fsdb_pub_sub",
        "//fboss/fsdb/common:flags",
        "//fboss/fsdb/if:fsdb_model",
        "//fboss/fsdb/if:fsdb_oper-cpp2-types",
        "//fboss/lib:common_file_utils",
        "//fboss/lib:common_utils",
        "//fboss/lib/config:fboss_config_utils",
        "//fboss/lib/phy:phy-cpp2-serialization",
        "//fboss/lib/phy:phy-cpp2-types",
        "//fboss/lib/phy:prbs-cpp2-types",
        "//fboss/lib/thrift_service_client:thrift-service-client",
        "//fboss/mka_service/if/facebook:mka_config-cpp2-types",
        "//fboss/mka_service/if/facebook:mka_service_thrift-cpp2-services",
        "//fboss/qsfp_service/fsdb/facebook/test:fsdb-test-utils",
        "//fboss/qsfp_service/if:transceiver-cpp2-serialization",
        "//fboss/qsfp_service/if:transceiver-cpp2-types",
        "//fboss/qsfp_service/lib:qsfp-service-client",
        "//folly:network_address",
        "//folly:random",
        "//folly:string",
        "//folly:subprocess",
        "//folly/debugging/exception_tracer:exception_tracer",
        "//folly/io/async:scoped_event_base_thread",
        "//folly/json:dynamic",
        "//folly/logging:logging",
        "//folly/system:shell",
        "//thrift/lib/cpp/util:enum_utils",
        "//thrift/lib/cpp2/async:rocket_client_channel",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
    exported_external_deps = [
        "gflags",
        ("boost", None, "boost_container"),
    ],
)

cpp_library(
    name = "macsec_test_utils",
    srcs = [
        "facebook/MacsecTestUtils.cpp",
    ],
    exported_deps = [
        "//fboss/agent/test:resourcelibutil",
        "//fboss/facebook/mka_service/mka_module:mka_structs",
        "//fboss/mka_service/if/facebook:mka_config-cpp2-types",
        "//fboss/mka_service/if/facebook:mka_service_thrift-cpp2-services",
    ],
)

cpp_library(
    name = "dependency_tests",
    srcs = [
        "DependencyTest.cpp",
        "LacpSanityTests.cpp",
        "LinkTest.cpp",
        "LinkTestUtils.cpp",
        "facebook/MacsecSanityTests.cpp",
        "facebook/MacsecTest.cpp",
    ],
    link_whole = True,
    # Will need symbols from bcm, sai layers. Those
    # will come when we build bcm/sai link test bins
    undefined_symbols = True,
    exported_deps = [
        "fbsource//third-party/googletest:gtest",
        ":link_test_production_features-cpp2-types",
        "//common/base:proc",
        "//fboss/agent:core",
        "//fboss/agent:fboss-error",
        "//fboss/agent:fboss-types",
        "//fboss/agent:load_agent_config",
        "//fboss/agent:main-common",
        "//fboss/agent:platform_base",
        "//fboss/agent/hw:hardware_stats-cpp2-types",
        "//fboss/agent/hw:hw_switch_warmboot_helper",
        "//fboss/agent/hw/test:config_factory",
        "//fboss/agent/hw/test:hw_packet_utils",
        "//fboss/agent/hw/test:hw_qos_utils",
        "//fboss/agent/hw/test:hw_test_ecmp_utils",
        "//fboss/agent/hw/test:load_balancer_utils",
        "//fboss/agent/platforms/common:platform_mapping",
        "//fboss/agent/state:state",
        "//fboss/agent/state:state_utils",
        "//fboss/agent/test:agent_test",
        "//fboss/agent/test:ecmp_helper",
        "//fboss/agent/test:resourcelibutil",
        "//fboss/agent/test:trunk_utils",
        "//fboss/agent/test/utils:copp_test_utils",
        "//fboss/agent/test/utils:qos_test_utils",
        "//fboss/facebook/mka_service/mka_module:mka_structs",
        "//fboss/lib:common_file_utils",
        "//fboss/lib:common_utils",
        "//fboss/lib/config:fboss_config_utils",
        "//fboss/lib/phy:phy-cpp2-serialization",
        "//fboss/lib/phy:phy-cpp2-types",
        "//fboss/lib/thrift_service_client:thrift-service-client",
        "//fboss/mka_service/if/facebook:mka_config-cpp2-types",
        "//fboss/mka_service/if/facebook:mka_service_thrift-cpp2-services",
        "//fboss/qsfp_service/if:transceiver-cpp2-serialization",
        "//fboss/qsfp_service/lib:qsfp-service-client",
        "//folly:string",
        "//folly:subprocess",
        "//folly/debugging/exception_tracer:exception_tracer",
        "//folly/io/async:scoped_event_base_thread",
        "//folly/json:dynamic",
        "//folly/logging:logging",
        "//thrift/lib/cpp2/async:rocket_client_channel",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
    exported_external_deps = [
        "gflags",
        ("boost", None, "boost_container"),
    ],
)

cpp_library(
    name = "agent_ensemble_link_tests",
    srcs = [
        "AgentEnsembleDependencyTest.cpp",
        "AgentEnsembleEmptyLinkTest.cpp",
        "AgentEnsembleFabricLinkTests.cpp",
        "AgentEnsembleLacpSanityTests.cpp",
        "AgentEnsembleLinkSanityTests.cpp",
        "AgentEnsembleLinkTest.cpp",
        "AgentEnsembleMacLearningTests.cpp",
        "AgentEnsembleOpenBmcUpgradeTests.cpp",
        "AgentEnsembleOpticsTest.cpp",
        "AgentEnsemblePhyInfoTest.cpp",
        "AgentEnsemblePrbsTest.cpp",
        "AgentEnsemblePtpTests.cpp",
        "AgentEnsembleSpeedChangeTest.cpp",
        "LinkTestUtils.cpp",
        "facebook/AgentEnsembleFsdbTests.cpp",
        "facebook/AgentEnsembleMacsecFsdbTests.cpp",
        "facebook/AgentEnsembleMacsecSanityTests.cpp",
        "facebook/AgentEnsembleMacsecSessionTests.cpp",
        "facebook/AgentEnsembleMacsecStatTests.cpp",
        "facebook/AgentEnsembleMacsecTest.cpp",
        "facebook/AgentEnsembleQsfpFsdbTests.cpp",
    ],
    link_whole = True,
    undefined_symbols = True,
    exported_deps = [
        "fbsource//third-party/googletest:gtest",
        ":link_test_production_features-cpp2-types",
        "//common/base:proc",
        "//fboss/agent:agent_features",
        "//fboss/agent:agent_stats-cpp2-types",
        "//fboss/agent:asic_utils",
        "//fboss/agent:core",
        "//fboss/agent:fboss-error",
        "//fboss/agent:fboss-types",
        "//fboss/agent:load_agent_config",
        "//fboss/agent:packet",
        "//fboss/agent:platform_base",
        "//fboss/agent:switchid_scope_resolver",
        "//fboss/agent/hw:hardware_stats-cpp2-types",
        "//fboss/agent/hw/test:config_factory",
        "//fboss/agent/packet:packet",
        "//fboss/agent/packet:packet_factory",
        "//fboss/agent/platforms/common:platform_mapping",
        "//fboss/agent/state:state",
        "//fboss/agent/state:state_utils",
        "//fboss/agent/test:agent_ensemble_test",
        "//fboss/agent/test:ecmp_helper",
        "//fboss/agent/test:resourcelibutil",
        "//fboss/agent/test:trunk_utils",
        "//fboss/agent/test:utils",
        "//fboss/agent/test/utils:copp_test_utils",
        "//fboss/agent/test/utils:load_balancer_test_utils",
        "//fboss/agent/test/utils:packet_snooper",
        "//fboss/agent/test/utils:pkt_test_utils",
        "//fboss/agent/test/utils:port_test_utils",
        "//fboss/agent/test/utils:qos_test_utils",
        "//fboss/agent/test/utils:trap_packet_utils",
        "//fboss/facebook/mka_service/fsdb/tests:MKAFsdbTestUtils",
        "//fboss/facebook/mka_service/mka_module:mka_structs",
        "//fboss/fsdb/client:fsdb_pub_sub",
        "//fboss/fsdb/common:flags",
        "//fboss/fsdb/if:fsdb_model",
        "//fboss/fsdb/if:fsdb_oper-cpp2-types",
        "//fboss/lib:common_file_utils",
        "//fboss/lib:common_utils",
        "//fboss/lib/config:fboss_config_utils",
        "//fboss/lib/phy:phy-cpp2-serialization",
        "//fboss/lib/phy:phy-cpp2-types",
        "//fboss/lib/phy:prbs-cpp2-types",
        "//fboss/lib/thrift_service_client:thrift-service-client",
        "//fboss/mka_service/if/facebook:mka_config-cpp2-types",
        "//fboss/mka_service/if/facebook:mka_service_thrift-cpp2-services",
        "//fboss/qsfp_service/fsdb/facebook/test:fsdb-test-utils",
        "//fboss/qsfp_service/if:transceiver-cpp2-serialization",
        "//fboss/qsfp_service/if:transceiver-cpp2-types",
        "//fboss/qsfp_service/lib:qsfp-service-client",
        "//folly:network_address",
        "//folly:random",
        "//folly:string",
        "//folly:subprocess",
        "//folly/debugging/exception_tracer:exception_tracer",
        "//folly/io/async:scoped_event_base_thread",
        "//folly/json:dynamic",
        "//folly/logging:logging",
        "//folly/system:shell",
        "//thrift/lib/cpp/util:enum_utils",
        "//thrift/lib/cpp2/async:rocket_client_channel",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
    exported_external_deps = [
        "gflags",
        ("boost", None, "boost_container"),
    ],
)

[
    cpp_binary(
        name = "bcm_link_test{}".format(to_impl_suffix(sdk)),
        srcs = [
            "BcmLinkTests.cpp",
        ],
        linker_flags = [
            "--export-dynamic",
            "--unresolved-symbols=ignore-all",
        ],
        versions = to_versions(sdk),
        deps = [
            "fbsource//third-party/googletest:gtest",
            "//fboss/agent:main-bcm",
            "//fboss/agent/hw/bcm/tests:bcm_ecmp_utils",
            "//fboss/agent/hw/bcm/tests:bcm_packet_trap_helper",
            "//fboss/agent/hw/bcm/tests:bcm_qos_utils",
            "//fboss/agent/platforms/wedge:platform",
            "//fboss/agent/test/link_tests:link_tests",
        ],
        external_deps = [
            "gflags",
            "glog",
        ],
    )
    for sdk in BCM_SDKS
]

[
    cpp_binary(
        name = "agent_ensemble_bcm_link_test{}".format(to_impl_suffix(sdk)),
        srcs = [
            "AgentEnsembleBcmLinkTest.cpp",
        ],
        linker_flags = [
            "--export-dynamic",
            "--unresolved-symbols=ignore-all",
        ],
        versions = to_versions(sdk),
        deps = [
            "fbsource//third-party/googletest:gtest",
            "//fboss/agent:main-bcm",
            "//fboss/agent:setup_thrift_prod",
            "//fboss/agent/hw/bcm/tests:agent_hw_test_thrift_handler",
            "//fboss/agent/hw/bcm/tests:bcm_ecmp_utils",
            "//fboss/agent/platforms/wedge:platform",
            "//fboss/agent/test:mono_agent_ensemble",
            "//fboss/agent/test/link_tests:agent_ensemble_link_tests",
        ],
        external_deps = [
            "gflags",
            "glog",
        ],
    )
    for sdk in BCM_SDKS
]

[
    cpp_binary(
        name = "bcm_dependency_test{}".format(to_impl_suffix(sdk)),
        srcs = [
            "BcmLinkTests.cpp",
        ],
        linker_flags = [
            "--export-dynamic",
            "--unresolved-symbols=ignore-all",
        ],
        versions = to_versions(sdk),
        deps = [
            "fbsource//third-party/googletest:gtest",
            "//fboss/agent:main-bcm",
            "//fboss/agent/hw/bcm/tests:bcm_ecmp_utils",
            "//fboss/agent/hw/bcm/tests:bcm_packet_trap_helper",
            "//fboss/agent/hw/bcm/tests:bcm_qos_utils",
            "//fboss/agent/platforms/wedge:platform",
            "//fboss/agent/test/link_tests:dependency_tests",
        ],
        external_deps = [
            "gflags",
            "glog",
        ],
    )
    for sdk in BCM_SDKS
]

thrift_library(
    name = "link_test_production_features",
    go_thrift_namespaces = {
        "link_test_production_features.thrift": "neteng.fboss.link_test_production_features",
    },
    languages = [
        "cpp2",
        "go",
        "py3-deprecated",
        "py-deprecated-asyncio",
        "rust",
        "py-deprecated",
        "python",
    ],
    py3_namespace = "neteng.fboss",
    py_asyncio_base_module = "neteng.fboss.asyncio",
    py_base_module = "neteng.fboss",
    thrift_cpp2_options = "json",
    thrift_py_options = "json,sort_keys",
    thrift_rust_options = [
        "deprecated_default_enum_min_i32",
        "serde",
    ],
    thrift_srcs = {"link_test_production_features.thrift": []},
    deps = [
    ],
)

all_sai_link_test_binaries()
